﻿using System;
using System.IO;
using Newtonsoft.Json;
using WeiSha.Core.Images;

namespace WeiSha.Core.Param.Method
{
	// Token: 0x02000038 RID: 56
	[JsonObject(0)]
	public class _Path
	{
		// Token: 0x06000257 RID: 599 RVA: 0x00010BA4 File Offset: 0x0000EDA4
		public _Path(string root, string path)
		{
			bool flag = string.IsNullOrEmpty(root);
			if (!flag)
			{
				path = (string.IsNullOrWhiteSpace(path) ? "" : path);
				this._value = path;
				bool flag2 = root == null;
				if (flag2)
				{
					root = "/";
				}
				bool flag3 = root.Length < 1;
				if (flag3)
				{
					root = "/";
				}
				string text = root.Substring(root.Length - 1, 1);
				bool flag4 = text != "\\" && text != "/";
				if (flag4)
				{
					root += "/";
				}
				this._path = root + path;
				this._virtualPath = root + path;
				bool flag5 = !Directory.Exists(this.Physics);
				if (flag5)
				{
					Directory.CreateDirectory(this.Physics);
				}
			}
		}

		// Token: 0x170000EC RID: 236
		// (get) Token: 0x06000258 RID: 600 RVA: 0x00010CA4 File Offset: 0x0000EEA4
		public string Physics
		{
			get
			{
				return Server.MapPath(this._virtualPath);
			}
		}

		// Token: 0x170000ED RID: 237
		// (get) Token: 0x06000259 RID: 601 RVA: 0x00010CC4 File Offset: 0x0000EEC4
		public string Virtual
		{
			get
			{
				return Server.VirtualPath(this._virtualPath);
			}
		}

		// Token: 0x170000EE RID: 238
		// (get) Token: 0x0600025A RID: 602 RVA: 0x00010CE4 File Offset: 0x0000EEE4
		public string String
		{
			get
			{
				return this._value;
			}
		}

		// Token: 0x170000EF RID: 239
		// (get) Token: 0x0600025B RID: 603 RVA: 0x00010CFC File Offset: 0x0000EEFC
		public ulong Length
		{
			get
			{
				return this.getLength(this._path);
			}
		}

		// Token: 0x0600025C RID: 604 RVA: 0x00010D1C File Offset: 0x0000EF1C
		private ulong getLength(string path)
		{
			bool flag = !Directory.Exists(path);
			ulong num;
			if (flag)
			{
				num = 0UL;
			}
			else
			{
				ulong num2 = 0UL;
				DirectoryInfo directoryInfo = new DirectoryInfo(path);
				foreach (FileInfo fileInfo in directoryInfo.GetFiles())
				{
					num2 += (ulong)fileInfo.Length;
				}
				foreach (DirectoryInfo directoryInfo2 in directoryInfo.GetDirectories())
				{
					num2 += this.getLength(directoryInfo2.FullName);
				}
				num = num2;
			}
			return num;
		}

		// Token: 0x0600025D RID: 605 RVA: 0x00010DAC File Offset: 0x0000EFAC
		public string GetSize(ulong size)
		{
			string text = "";
			bool flag = size < 1024UL;
			if (flag)
			{
				text = size.ToString() + " Bit";
			}
			else
			{
				double num = size / 1024UL;
				num = Math.Round(num * 100.0) / 100.0;
				bool flag2 = num < 1024.0;
				if (flag2)
				{
					text = num.ToString() + " Kb";
				}
				else
				{
					double num2 = num / 1024.0;
					num2 = Math.Round(num2 * 100.0) / 100.0;
					bool flag3 = num2 < 1024.0;
					if (flag3)
					{
						text = num2.ToString() + " Mb";
					}
				}
			}
			return text;
		}

		// Token: 0x0600025E RID: 606 RVA: 0x00010E90 File Offset: 0x0000F090
		public bool DeleteFile(string filename)
		{
			bool flag = string.IsNullOrWhiteSpace(filename);
			bool flag2;
			if (flag)
			{
				flag2 = false;
			}
			else
			{
				string physics = this.Physics;
				bool flag3 = !Directory.Exists(physics);
				if (flag3)
				{
					flag2 = false;
				}
				else
				{
					string text = physics + filename;
					string text2 = Name.ToSmall(text);
					try
					{
						bool flag4 = File.Exists(text);
						if (flag4)
						{
							File.Delete(text);
						}
						bool flag5 = File.Exists(text2);
						if (flag5)
						{
							File.Delete(text2);
						}
					}
					catch (Exception ex)
					{
						throw ex;
					}
					flag2 = true;
				}
			}
			return flag2;
		}

		// Token: 0x0600025F RID: 607 RVA: 0x00010F20 File Offset: 0x0000F120
		public bool DeleteDirectory(string dir)
		{
			bool flag = string.IsNullOrWhiteSpace(dir);
			bool flag2;
			if (flag)
			{
				flag2 = false;
			}
			else
			{
				string text = this.Physics + dir;
				bool flag3 = !Directory.Exists(text);
				if (flag3)
				{
					flag2 = false;
				}
				else
				{
					try
					{
						Directory.Delete(text, true);
						flag2 = true;
					}
					catch (Exception ex)
					{
						throw ex;
					}
				}
			}
			return flag2;
		}

		// Token: 0x040000B0 RID: 176
		private string _path = "";

		// Token: 0x040000B1 RID: 177
		private string _virtualPath = "";

		// Token: 0x040000B2 RID: 178
		private string _value = "";
	}
}
